package com.gemantic.task.job;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.gemantic.task.dto.DbTaskJobParams;
import com.gemantic.task.service.TaskService;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;

import cn.hutool.core.date.DateUtil;

/**
 * 捞取数据库任务执行
 */
@Service
public class DbTaskJobHandler extends BaseJobHandler<DbTaskJobParams> {
    @Autowired
    private TaskService taskService;

    @Override
    public void process(DbTaskJobParams paramDto) {
        if (paramDto == null) {
            return;
        }
        taskService.runFromDb(paramDto);
    }


    @XxlJob(value = "DbTaskJob")
    public void process2() {
        String param = XxlJobHelper.getJobParam();
        if (param == null) {
            return;
        }

        taskService.runFromDb(JSON.parseObject(param, DbTaskJobParams.class));
        XxlJobHelper.handleSuccess("当前任务调度完成: "+ DateUtil.now());
    }

}
